package net.lainiao.morethread.Chapter3.demo4;

import java.util.concurrent.CyclicBarrier;

/**
 * Created by Administrator on 2017/3/1.
 */
public class Main {
    public static void main(String[] args) {
        final int ROWS=10000;
        final int NUMBERS=1000;
        final int SEARCH=5;
        final int PARTICIPANTS=5;
        final int LINES_PARTICIPANT=2000;
        MatrixMock mock=new MatrixMock(ROWS,NUMBERS,SEARCH);
        Result result=new Result(ROWS);
        Grouper grouper=new Grouper(result);
        CyclicBarrier barrier=new CyclicBarrier(5,grouper);
        Searcher[] searchers=new Searcher[PARTICIPANTS];
        int start=0;
        int end=0;
        for (int i = 0; i < PARTICIPANTS; i++) {
            end=start+LINES_PARTICIPANT;
            Searcher tem=new Searcher(start,end,mock,result,SEARCH,barrier);
            start=end;
            searchers[i]=tem;
            Thread thread=new Thread(tem);
            thread.start();
        }
        System.out.println("Main方法结束~!");
    }
}
